<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    protected $guarded = ['id'];
    protected $appends = ['user_status','shop_status','status_style']; 

    private $statusTxt = [
        // 已确认之后的取消      
       
        '-1' => ['user'=>'已取消','shop'=>'已取消','style'=>'warning'],
    	'1' => ['user'=>'待确认','shop'=>'待确认','style'=>'primary'],
    	//线上付款才有用
        '2' => ['user'=>'待付定金','shop'=>'已确认','style'=>'success'], 
    	'3' => ['user'=>'已付定金','shop'=>'已付定金','style'=>'success'], 
        //配送订单需要传图
        '4' => ['user'=>'待收货','shop'=>'已上传图片','style'=>'success'],
        // 配送的订单
    	'5' => ['user'=>'待付款','shop'=>'已配送','style'=>'success'],

        '90' => ['user'=>'同意取消订单','shop'=>'同意取消订单','style'=>'success'],

    	'100' => ['user'=>'已收货','shop'=>'待评价','style'=>'success'],
    	'200' => ['user'=>'已评价','shop'=>'已评价','style'=>'success'],
    ];
    public function shop()
    {
    	return $this->belongsTo(Shop::class);
    }

    public function address()
    {
        return $this->belongsTo(UserAddress::class);
    }

    public function user()
    {
    	return $this->belongsTo(User::class);
    }

    public function products()
    {
    	return $this->hasMany(OrderProduct::class);
    }

    public function getUserStatusAttribute()
    {    	
    	return $this->statusTxt[$this->status]['user'];
    }

    public function getShopStatusAttribute()
    {    	
    	return $this->statusTxt[$this->status]['shop'];
    }

    public function getStatusStyleAttribute()
    {       
        return $this->statusTxt[$this->status]['style'];
    }

    public function getTotalMoneyTxtAttribute()
    {       
        return $this->total_money/100;
    }

    

    public function getPrepayMoneyTxtAttribute()
    {
        return $this->prepay_money/100;
    }
}
